package com.itheima.clientAndService01;

import java.util.Comparator;
import java.util.TreeMap;

public class TreeMapClass01 {
    public static void main(String[] args) {
        TreeMap<Student,String> tm = new TreeMap<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                int result = o2.getAge() - o1.getAge();
                result = result == 0 ? o2.getName().compareTo(o1.getName()) : result;
                return result;
            }
        });

        Student stu1 = new Student("zhangsan", 23);
        Student stu2 = new Student("xiaohei", 22);
        Student stu3 = new Student("xiaomei", 23);

        tm.put(stu1,"江苏");
        tm.put(stu2,"陕西");
        tm.put(stu3,"成都");

        tm.forEach((key,value) -> {
            System.out.println(key + "----" + value);
        });
    }
}
